package com.ty.controller;

import com.ty.entity.Order;
import com.ty.entity.OrderAddr;
import com.ty.service.OrderAddrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "订单信息对象功能接口")
@RestController
@RequestMapping("/api/orderaddr")
public class OrderAddrController extends BaseController{

    @Autowired
    OrderAddrService orderAddrService;


    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/addr/queryById")
    public ResponseEntity<Order> queryById(Integer orderDetail){
        List<Order> orderList = (List<Order>) orderAddrService.queryById(orderDetail);
        return ResponseEntity.ok((Order) orderList);
    }

    @ApiOperation("订单地址生成")
    @PostMapping("/addr/insert")
    public ResponseEntity<Integer> insert (OrderAddr orderAddr){
        int rs =orderAddrService.insert(orderAddr);
        return ResponseEntity.ok(rs);
    }

    @ApiOperation("订单地址信息更新")
    @PostMapping("/addr/update")
    public ResponseEntity<Integer> update(OrderAddr orderAddr){
        int rs = orderAddrService.update(orderAddr);
        return ResponseEntity.ok(rs);
    }

    @ApiOperation("删除订单")
    @DeleteMapping("/addr/delete")
    public ResponseEntity<Boolean> delete(Integer orderAddrId){
        boolean rs = orderAddrService.deleteById(orderAddrId);
        return ResponseEntity.ok(rs);
    }


}
